#include <allegro.h>
#include <stdio.h>
#include "deplacementM.h"

#define NB_IMAGES 3

int main() {

	char chemin_background[]="../images/background.bmp";

	BITMAP *Buffer;
	BITMAP *Background=NULL;
	
	MB mini;

	int compteur;

	/* General initialization function */
	allegro_init();
	if (install_keyboard() == -1) {
		allegro_message("Error! %s", allegro_error);
		return (-1);
	}
	set_color_depth(16);
	if (set_gfx_mode(GFX_AUTODETECT_WINDOWED, 600, 800, 0, 0) != 0) {
		set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); /* here’s the command for text mode */
		allegro_message("Unable to initialize video mode!\n%s\n", allegro_error);
		return (1);
	}

	Buffer = create_bitmap(SCREEN_W, SCREEN_H);
	//loading images
	//loading MB
	load_MB(&mini);
	//loading background + background collision
	Background=load_background_bmp(chemin_background);
	//loading background collision Map


	//init position & direction
	compteur = 0;
	init_MB(&mini);

	while (!key[KEY_ESC]) {

	//vider le buffer
		clear_bitmap(Buffer);

	//moving MB
		move_MB(&mini,&compteur,Background);

	//drawing background
		draw_background(Background,Buffer);

	//drawing MB
		draw_sprite(Buffer, mini.img_face, mini.x, mini.y);
		//draw_MB(mini,Buffer,compteur);

	//blit Buffer to screen
		blit(Buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);

		if (compteur == 10000)
			compteur = 0;
	}
	//destroy MB
	destroy_MB(&mini);
	destroy_background(Background);
	destroy_bitmap(Buffer);
	return (0);
}
END_OF_MAIN();
